var app = new Vue({
    el: '.growth',
    data: {
        coinhistory: { //资金历史 分页参数
            userId: 1,
            coin: '',
            type: '',
            p: 1,
            s: 10,
            list: []
        },
        showItem: 5,
        HPS: "HPS",
        ETH: "ETH",
        BTC: "BTC",
        HSR: "HSR",
        HAND: "HAND",
        HART: "HART",
        MOT: "MOT",
        allpage: '',
        theuser:'',
        information:'',
        capitalType:null,
        typebool:false,
        coinType:null,
        coinTypee:false,
        coinbool:false,
        loading:false
    },
    // s: this.coinhistory.s
    computed: {
        onUpload(e) {
            var formData = new FormData();
            formData.append('file', e.target.files[0]);
        },
    },
    created() {
        let lang = this.getCookie("lang");
        if(lang == "en_US"){
            this.capitalType = 'Fund Type' 
            this.coinType = 'Currency Type'
        }else if(lang == "zh_TW"){
            this.capitalType = '類型' 
            this.coinType = '幣種'
        }else{
            this.capitalType = '类型' 
            this.coinType = '币种'
        }
        this.location = location.href.split('/')[0]+'//'+location.href.split('/')[2]+'/'
        let params = {
            coin: this.coinhistory.coin,
            type: this.coinhistory.type,
            p: this.coinhistory.p,
            s: this.coinhistory.s
        }
        this.getcoinPostHistory(params)
    },
    mounted() {
        let _this = this
        this.loading=true
        window.addEventListener('scroll',function(){  
            let scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
            if(scrollTop + window.innerHeight >= document.body.offsetHeight) { 
                setTimeout(() => {
                    _this.coinhistory.s += 8
                    let params = {
                        coin: _this.coinhistory.coin,
                        type: _this.coinhistory.type,
                        p: _this.coinhistory.p,
                        s: _this.coinhistory.s
                    }
                    _this.getcoinPostHistory(params)
                },1000)   
            } 
        })
    },
    methods: {
        changeSelect(k) { //切换选项框
            if(k==1){
                this.typebool = !this.typebool
                this.coinbool = false
            }else if(k==2){
                this.coinbool = !this.coinbool
                this.typebool = false
            }
        },
        changefinancetype(index) {  //切换资金类型
            let str = document.getElementsByClassName('typetext' + index)[0].innerHTML
            this.capitalType = str
            this.coinhistory.p = 1
            this.coinhistory.s = 10
            if(index==0){
                this.coinhistory.type=''
            }else if(index==1){
                this.coinhistory.type='game'
            }else if(index==2){
                this.coinhistory.type='deposit'
            }else if(index==3){
                this.coinhistory.type='withdraw'
            }else if(index==4){
                this.coinhistory.type='transfer'
            }else if(index==5){
                this.coinhistory.type='ag'
            }else if(index==6){
                this.coinhistory.type='commission'
            }else if(index==7){
                this.coinhistory.type='others'
            }else if(index==8){
                this.coinhistory.type='sb'
            }
            let params = {
                coin: this.coinhistory.coin,
                type: this.coinhistory.type,
                p: this.coinhistory.p,
                s: this.coinhistory.s
            }
            this.getcoinPostHistory(params)
            this.typebool = false
        },
        changecointype(coin, index) { //切换币种
            if(coin==""){
                this.coinTypee =false
            }else{
               this.coinTypee =true
           }
            this.coinType = coin
            this.coinhistory.coin = coin
            this.coinhistory.p = 1
            this.coinhistory.s = 10
            let params = {
                coin: this.coinhistory.coin,
                type: this.coinhistory.type,
                p: this.coinhistory.p,
                s: this.coinhistory.s
            }
            this.getcoinPostHistory(params)
            this.coinbool = false
        },
        getTime: function (time) { //计算时间
            var t = new Date(time) 
            function charLeftAll(n) {
                if (n < 10) return "0" + n;
                else return n;
            }
            return t.getFullYear() + '-' + charLeftAll((t.getMonth() + 1)) + '-' + charLeftAll(t.getDate()) + '  ' +
                charLeftAll(t.getHours()) + ':' + charLeftAll(t.getMinutes()) + ':' + charLeftAll(t.getSeconds())
        },
        getcoinPostHistory(obj = null) { //获取资金历史
            axios.post('/coin/coinPostHistory', obj).then((res) => {
                this.coinhistory.list = this.filtercoinhistorylist(res.data.data.list,res.data.data.rate)
                this.coinhistory.list = res.data.data.list
                this.allpage = res.data.data.pages
            })
        },
        filtercoinhistorylist(arr1,arr2){ //过滤资金历史数组
            if(arr1.length){
                arr1.forEach(ele => {
                    arr2.forEach(ele2 => {
                        if(ele2){
                            if(ele.type=='TRANSFER TO AG'&&`ag-rate-${ele.coin}`==ele2.dictKey){
                                let dictValue=ele2.dictValue?parseInt(ele2.dictValue):1
                                ele.agcompute=parseFloat(ele.amount)*dictValue
                            }else if(ele.type=='TRANSFER FROM AG'&&`ag-rate-${ele.coin}`==ele2.dictKey){
                                let dictValue=ele2.dictValue?parseInt(ele2.dictValue):1
                                ele.agcompute=parseFloat(ele.amount)*dictValue
                            }else if(ele.type=='TRANSFER TO SB'&&`ag-rate-${ele.coin}`==ele2.dictKey){
                                let dictValue=ele2.dictValue?parseInt(ele2.dictValue):1
                                ele.sbcompute=parseFloat(ele.amount)*dictValue
                            }else if(ele.type=='TRANSFER FROM SB'&&`ag-rate-${ele.coin}`==ele2.dictKey){
                                let dictValue=ele2.dictValue?parseInt(ele2.dictValue):1
                                ele.sbcompute=parseFloat(ele.amount)*dictValue
                            }
                        }
                    })
                })
                return arr1
            }else{
                return []
            }
        },
        closeinfo(){
            let timer=setInterval(() => {
                document.getElementsByClassName('errorMessage')[0].className='errorMessage'
                clearInterval(timer)
                timer=null
            },2000)
            document.getElementsByClassName('errorMessage')[0].className='errorMessage fadeInUp'
            this.theuser="";
            this.information=""
            let BODY =document.getElementsByTagName("body")[0]
            BODY.style.overflowY=""
        },
        getCookie(cookiename) { //获取cookie
            var arr,
              reg = new RegExp("(^| )" + cookiename + "=([^;]*)(;|$)");
            if ((arr = document.cookie.match(reg))) {
              return unescape(arr[2]);
            } else {
              return null;
            }
        },
        filterStr(str){ //转换小写
            return str.toLowerCase()
        }
    }
})